package com.example.pro5_webflux_r2dbc_book;

import com.example.pro5_webflux_r2dbc_book.controllers.BookHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

//基于函数式编程的方式来实现路由和处理请求的逻辑。需要有一个路由类对应BookHandler中的处理路径.
@Configuration

public class BookHandlerRouterConfig {
    @Bean
    public RouterFunction<ServerResponse> route(BookHandler handler) {
        return RouterFunctions.route()
                .POST("/books", handler::addBook)
                .GET("/books", handler::getAllBooks)
                .GET("/books/{id}", handler::getBookById)
                .PUT("/books/{id}", handler::updateBook)
                .DELETE("/books/{id}", handler::deleteBook)
                .build();
    }

}
